import store from '@/store'
import router from '@/router'
/**
 * 关闭当前tab
 *
 * @returns {Boolean}
 */
export function CloseCurrentTab() {
  const visitedViews = store.state.tagsView.visitedViews;
  const activeName = this.$route.path;
  let view = visitedViews.find((item, index) => {
    return (item.path == activeName) & (index > 0);
  });
  if (view) {
    this.$tab.closePage(view).then(({
      visitedViews
    }) => {
      if (view.path === this.$route.path) {
        const latestView = visitedViews.slice(-1)[0];
        if (latestView) {
          router.push(latestView.fullPath);
        } else {
          if (view.name === 'Dashboard') {
            router.replace({
              path: '/redirect' + view.fullPath
            });
          } else {
            router.push('/');
          }
        }
      }
    });
  }
}
